﻿using OpenBlock.Block;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace OpenBlock.Terrain.Generators
{
    class SuperFlatGenerator : ITerrainGenerator
    {
        public void GenerateTerrain(ref Chunk chunk)
        {
            List<Vector3Int> grasses = new List<Vector3Int>();
            List<Vector3Int> dirts = new List<Vector3Int>();
            List<Vector3Int> stones = new List<Vector3Int>();
            for (int x = 0; x < Chunk.SIZE; x++)
            {
                int worldX = chunk.chunkPos.x * Chunk.SIZE + x;
                for (int z = 0; z < Chunk.SIZE; z++)
                {
                    int worldZ = chunk.chunkPos.z * Chunk.SIZE + z;
                    for (int y = 0; y < Chunk.SIZE; y++)
                    {
                        int worldY = chunk.chunkPos.y * Chunk.SIZE + y;
                        if (worldY == 10) grasses.Add(new Vector3Int(x, y, z));
                        else if (worldY < 10) dirts.Add(new Vector3Int(x, y, z));
                        else if (worldY < 5) stones.Add(new Vector3Int(x, y, z));
                        else continue;
                        /*if (worldY < 0) chunk.AddBlock(BlockState.RGB(Color.black), new Vector3Int(x, y, z));
                        else if (worldY < 15) chunk.AddBlock(new BlockState(BlockId.Stone), new Vector3Int(x, y, z));
                        else if (worldY < 16) chunk.AddBlock(new BlockState(BlockId.Grass), new Vector3Int(x, y, z));
                        else continue;*/
                    }
                }
            }

            chunk.BatchedAddBlock(new BlockState(BlockId.Grass), grasses.ToArray());
            chunk.BatchedAddBlock(new BlockState(BlockId.Dirt), dirts.ToArray());
            chunk.BatchedAddBlock(new BlockState(BlockId.Stone), stones.ToArray());
        }
    }
}
